<template>
    
    <el-popover  placement="bottom" width="150" trigger="click" class="" @show="doQuery">
        <!-- <el-row>
            <el-button @click="doQuery" type="primary" size="mini">刷新</el-button>
        </el-row>
        <el-divider></el-divider> -->
        <el-row v-for="(item,idx) in stockList" :key="idx">
            <span class="resspan ml10">{{item.code}}</span>
            <span class="resspan ml10">{{item.name}}</span>
        </el-row>
        <el-divider></el-divider>
        <el-row v-for="(item,idx) in zqList" :key="'zq'+idx">
            <span class="resspan ml10">{{item.code}}</span>
            <span class="resspan ml10">{{item.name}}</span>
        </el-row>

        <el-button slot="reference" type="text" class="ml10" size="mini"><span class="red">新股/新债</span></el-button>
    </el-popover>
</template>

<script>

export default {
    data() {
        return {
            key:"",
            stockList: [],
            zqList: [],
            curDate: this.$dayjs().format("YYYY-MM-DD"),
        }
    },
    inject: ['cfg',"isQry"],
    

    mounted() {
        this.doQuery();
    },

    methods: {
        doQuery(){
            this.queryStockInfo();
            this.queryZqInfo();
        },
        queryStockInfo(){
            this.stockList=[];
            this.$axios.get(`http://dcfm.eastmoney.com/em_mutisvcexpandinterface/api/js/get?type=XGSG_LB&token=70f12f2f4f091e459a279469fe49eca5&st=purchasedate,securitycode&sr=-1&p=1&ps=50&`+Math.random())
            .then((res) => {
                try{
                    var tmplist = res.data;
                    tmplist.map((item)=>{
                        if(item.purchasedate.indexOf(this.curDate)!=-1){
                            this.stockList.push({name:item.securityshortname,code:item.securitycode});
                        }
                    })
                }catch(ex){
                    this.$message.error(ex.message);
                }
            })
        },
        queryZqInfo(){
            this.zqList=[];
            this.$axios.get(`http://www.miaogu.com/quotes/kzz/index.php?&`+Math.random())
            .then((res) => {
                try{
                    var tmplist = res.data.list;
                    for(var i=tmplist.length-10;i<tmplist.length;i++){
                        var item = tmplist[i];
                        if(item.sub_date.indexOf(this.curDate)!=-1){
                            this.zqList.push({name:item.bond_name,code:item.bond_code});
                        }
                    }
                }catch(ex){
                    this.$message.error(ex.message);
                }
            })
        }
    }
}
</script>

<style lang="less" scoped>

    .resspan{
        display: inline-block;
        // min-width: 60px;
        text-align: right;
    }
</style>
